<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$url=$_REQUEST['url'];
$postdata=urldecode($_REQUEST['postdata']);
$callback=$_REQUEST['jsonpCallback'];
$cont=CurlOpen($url,$postdata);
echo "{$callback}($cont)";


function CurlOpen($url, $post = '', $cookie = '', $timeout = 10) {
    $ch = curl_init();
    $charset = 'utf-8';
    $u = parse_url($url);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    if ($u['scheme'] == 'https') {
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    }

    if ($post) {
        $header[] = 'Accept: */*';
        $header[] = 'Accept-Language: zh-cn,zh;q=0.5';
        $header[] = 'Content-Type: application/x-www-form-urlencoded';
       // $header[] = 'Accept-Encoding: gzip,deflate';
        $header[] = 'Accept-Charset: utf-8,GB2312;q=0.7,*;q=0.7';
        $header[] = 'User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20100101 Firefox/6.0.1';
        $header[] = 'Host: ' . $u['host'];
        //$header[] = 'Referer: http://www.baidu.com/';
        $header[] = 'Connection: Close';
        $header[] = 'Content-Length: ' . strlen($post);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    } else {
        $header[] = 'Accept: */*';
        $header[] = 'Accept-Language:  zh-cn,zh;q=0.5';
        $header[] = 'Content-type: text/html;charset=' . $charset;
        $header[] = 'Accept-Charset:utf-8,GB2312;q=0.7,*;q=0.7';
        $header[] = 'User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20100101 Firefox/6.0.1';
        $header[] = 'Host: ' . $u['host'];
        //$header[] = 'Referer: http://www.baidu.com/';
        $header[] = 'Connection: Close';
        $header[] = 'Cache-Control: no-cache';
        $header[] = 'Cookie: ' . $cookie;
        //$header[] = 'Accept-Encoding: gzip,deflate';
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_HTTPGET, 1);
    }
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_exec($ch);
    $info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if (intval($info, 10) != 200) {
        $rval = false;
    } else {
        $rval = curl_multi_getcontent($ch);
    }
    curl_close($ch);
    //$rval = mygzdecode($rval);
    return $rval;
}

?>